<template>
  <div class="content">
    <p>投标保证金</p>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
      :show-summary="true"
    >
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    getTenderDeposit
  } from '@/api/teambalance1'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'

  const datePay = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const receiveCompany = function(row, column) {
    if (row.receiveCompany) {
      let obj = {}
      obj = global.billUnitList.find((item) => {
        return item.value === row.receiveCompany // 筛选出匹配数据
      })
      return obj.label
    }
  }

  const dateReturn = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        if (time) {
          var date = new Date(time)
          return formatDate(date, 'yyyy-MM-dd')
        } else {
          return ''
        }
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const isReturn = {
    props: ['colConfig'],
    filters: {
      isReturn(type) {
        const returns = type ? '是' : '否'
        return returns
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | isReturn }}
      </span>
  </el-table-column>
  `
  }

  const payCertificate = {
    props: ['colConfig'],
    methods: {
      openVisible(label, src) {
        const msg = {
          label: label,
          src: src
        }
        this.$emit('openImgVisible', msg)
      }
    },
    filters: {},
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        <a v-if="scope.row[colConfig.prop]" @click="openVisible(colConfig.label,scope.row[colConfig.prop])">查看</a>
      </span>
  </el-table-column>
  `
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    props: ['viewDetailList'],
    data() {
      return {
        colConfigs: [
          { prop: 'tenderName', label: '投标项目名称', width: '350', fixed: true },
          { prop: 'teamName', label: '团队名称', width: '100' },
          { prop: 'amount', label: '保证金金额(万元)', width: '120' },
          { prop: 'returnPay', label: '退还金额(万元)', width: '100' },
          { prop: 'datePay', label: '打款时间', width: '100', component: datePay },
          { prop: 'receiveCompany', label: '打款单位', width: '150', formatter: receiveCompany },
          { prop: 'serviceFee', label: '资金周转费(元)', width: '120' },
          { prop: 'address', label: '详细地址', width: '150' },
          { prop: 'isReturn', label: '是否退还保证金', width: '120', component: isReturn },
          { prop: 'dateReturn', label: '退还时间', width: '100', component: dateReturn },
          { prop: 'totalServiceFee', label: '服务费(元)', width: '80' }
          // { prop: 'payCertificate', label: '支出凭证', width: '80', component: payCertificate }
        ],
        listLoading: true,
        dialogType: 0,
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        pca: pca,
        rules: {},
        visible: false
      }
    },
    created() {
    },
    computed: {
      global() {
        return global
      },
      teamId() {
        return this.$store.state.user.teamId
      },
      roleType() {
        return this.$store.state.user.roleType
      }
    },
    methods: {
      fetchData() {
        this.viewDetailList.pageNum = this.pageNum
        this.viewDetailList.pageSize = this.pageSize
        this.viewDetailList.amountType = 1
        this.listLoading = true
        getTenderDeposit(this.viewDetailList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      }
    },
    watch: {
      'viewDetailList': {
        handler(newValue, oldValue) {
          this.fetchData()
        },
        immediate: true
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .content {
    padding: 20px;
  }

</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
